package com.Apo1o.service.impl;

import com.Apo1o.entity.Notice;
import com.Apo1o.entity.User;
import com.Apo1o.entity.bfBasic;
import com.Apo1o.mapper.BfBasicMapper;
import com.Apo1o.service.BfBasicService;
import com.Apo1o.vo.PageResponse;
import com.Apo1o.vo.UserInfoVo;
import com.Apo1o.vo.bfBasicInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.Apo1o.utils.CommonUtils.setLikeWrapper;

/**
 * @Auther: Apo1o.
 * @Date: 2024/5/7-05-07-12:38
 * @Description： com.Apo1o.service.impl
 */
@Service
@RequiredArgsConstructor
public class BfBasicServiceImpl extends ServiceImpl<BfBasicMapper,bfBasic> implements BfBasicService {

    private final BfBasicMapper bfBasicMapper;
    @Override
    public PageResponse<bfBasic> findAllBfbasic(bfBasic bfBasic, Integer pageNum, Integer pageSize) {
        IPage<bfBasic> bfBasicIPage = new Page<>(pageNum, pageSize);
        QueryWrapper<bfBasic> wrapper = new QueryWrapper<>();
        bfBasicIPage = bfBasicMapper.selectPage(bfBasicIPage,wrapper);
        return PageResponse.<bfBasic>builder().data(bfBasicIPage.getRecords()).total(bfBasicIPage.getTotal()).build();
    }

    @Override
    public PageResponse<bfBasicInfoVo> getUser(Integer pageNo, Integer pageSize) {
        IPage<bfBasic> bfPage = new Page<>(pageNo, pageSize);



        QueryWrapper<bfBasic> wrapper = new QueryWrapper<>();

        wrapper.orderByDesc("id");


        bfPage = bfBasicMapper.selectPage(bfPage, wrapper);
        List<bfBasicInfoVo> records = bfPage.getRecords().stream().map(bfBasicInfoVo::fromBasic).collect(Collectors.toList());

        return PageResponse.<bfBasicInfoVo>builder().data(records).total(bfPage.getTotal()).build();
    }
}
